package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.domain.entity.SlLevel;
import com.ruoyi.sl.service.ISlLevelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 级别Controller
 * 
 * @author admin
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/sl/level")
public class SlLevelController extends BaseController
{
    @Autowired
    private ISlLevelService slLevelService;

    /**
     * 查询级别列表
     */
    @PreAuthorize("@ss.hasPermi('sl:level:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlLevel slLevel)
    {
        startPage();
        List<SlLevel> list = slLevelService.selectSlLevelList(slLevel);
        return getDataTable(list);
    }

    /**
     * 导出级别列表
     */
    @PreAuthorize("@ss.hasPermi('sl:level:export')")
    @Log(title = "级别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlLevel slLevel)
    {
        List<SlLevel> list = slLevelService.selectSlLevelList(slLevel);
        ExcelUtil<SlLevel> util = new ExcelUtil<SlLevel>(SlLevel.class);
        util.exportExcel(response, list, "级别数据");
    }

    /**
     * 获取级别详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:level:query')")
    @GetMapping(value = "/{levelId}")
    public AjaxResult getInfo(@PathVariable("levelId") Long levelId)
    {
        return success(slLevelService.selectSlLevelByLevelId(levelId));
    }

    /**
     * 新增级别
     */
    @PreAuthorize("@ss.hasPermi('sl:level:add')")
    @Log(title = "级别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlLevel slLevel)
    {
        slLevel.setCreateBy(getUsername());
        return toAjax(slLevelService.insertSlLevel(slLevel));
    }

    /**
     * 修改级别
     */
    @PreAuthorize("@ss.hasPermi('sl:level:edit')")
    @Log(title = "级别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlLevel slLevel)
    {
        slLevel.setUpdateBy(getUsername());
        return toAjax(slLevelService.updateSlLevel(slLevel));
    }

    /**
     * 删除级别
     */
    @PreAuthorize("@ss.hasPermi('sl:level:remove')")
    @Log(title = "级别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{levelIds}")
    public AjaxResult remove(@PathVariable Long[] levelIds)
    {
        return toAjax(slLevelService.deleteSlLevelByLevelIds(levelIds));
    }
}
